#!/usr/bin/python2
# -*- coding: utf8 -*-
from PyQt4 import QtCore, QtGui, Qt, QtDeclarative
from models.JobsModel import JobsModel
from models.BaseTimeModel import BaseTimeModel

class FullDayJobModel(BaseTimeModel):
    HOUR_ROLE = 0
    MIN_ROLE = 1
    JOBS_ROLE = 2

    def __init__(self, db, fromDate=QtCore.QDate.currentDate(), parent=None):
        BaseTimeModel.__init__(self, fromDate, parent)
        self.setRoleNames({self.HOUR_ROLE: 'hours', self.MIN_ROLE: 'minutes', self.JOBS_ROLE: 'jobs'})
        self._db = db

    def data(self, index, role):
        if not index.isValid: return QtCore.QVariant()
        row = index.row() + 6
        if role == self.HOUR_ROLE:
            time = QtCore.QDateTime(self._fromDate).addSecs(row*60*60)
            return  time.time().hour()
        if role == self.MIN_ROLE:
            return 0
        if role == self.JOBS_ROLE:
            toDate = QtCore.QDateTime(self._fromDate)
            toTime = toDate.addSecs(60*60*(row+1)).toTime_t()
            fromDate = QtCore.QDateTime(self._fromDate)
            fromTime = fromDate.addSecs(60*60*row).toTime_t()
            jobModel = JobsModel(self._db, fromTime, toTime, 9999, self)
            return QtCore.QVariant(jobModel)
        return QtCore.QVariant()

    def rowCount(self, parent=QtCore.QModelIndex()):
        return 12
